package com.example.wallpaper;

import androidx.annotation.NonNull;
import androidx.appcompat.app.AppCompatActivity;
import androidx.fragment.app.Fragment;
import androidx.fragment.app.FragmentManager;

import android.os.Bundle;
import android.os.Handler;
import android.os.Message;
import android.util.Log;

import com.example.wallpaper.tools.HttpUtil;

public class WallActivity extends AppCompatActivity implements WallFragment.Callbacks{

    private static final String TAG = "MainActivity";

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_wall);
        FragmentManager fm = getSupportFragmentManager();
        Fragment fragment = fm.findFragmentById(R.id.fragment_container);
        if(fragment==null){
            fragment = new WallFragment();
            fm.beginTransaction()
                    .add(R.id.fragment_container,fragment)
                    .commit();
        }
    }

    /**详情页的跳转逻辑*/
    @Override
    public void onDetail(String imgUrl) {
        FragmentManager fm = getSupportFragmentManager();
        Fragment fragment = fm.findFragmentById(R.id.fragment_container);
        if(fragment==null){
            fragment = WallViewFragment.newInstance(imgUrl);
            fm.beginTransaction()
                    .addToBackStack(null)
                    .add(R.id.fragment_container,fragment)
                    .commit();
        }else{
            fragment = WallViewFragment.newInstance(imgUrl);
            fm.beginTransaction()
                    .addToBackStack(null)
                    .replace(R.id.fragment_container,fragment)
                    .commit();
        }
    }
}